# -*- coding:utf-8 -*-
__date__ = '2022/6/24 9:42 下午'

'''
长度最小的子数组

输入：s = 7, nums = [2,3,1,2,4,3] 输出：2 解释：子数组 [4,3] 是该条件下的长度最小的子数组
'''


class Solution:
  def min_sub_list(self, nums, target):
    # 和
    Sum = 0
    # 索引记录
    index = 0
    # 返回值:最小长度
    result = float('inf')
    for i in range(len(nums)):
      Sum += nums[i]
      while Sum >= target:
        result = min(result, i - index + 1)
        Sum -= nums[index]
        index += 1
    print(result)


if __name__ == '__main__':
  Solution = Solution()
  target = 7
  nums = [2, 3, 1, 2, 4, 3, 5]
  Solution.min_sub_list(nums, target)
